<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>表单验证规则</title>
        <#include "/pubHeadStyle.html">
        <script src="${ctx}/extends/jquery.min.js" type="text/javascript"></script>
    </head>
    <body>
        <div class="ccpui-tablesize" style="padding:10px;">
            <table id="formRule" lay-filter="formRule"></table>
        </div>
        <script type="text/html" id="formRuleToolsBar">
            <div class="ccpui-enterSel">
                <div class="layui-btn-container">
                    <a class="layui-btn layui-btn-sm" lay-event="query">
                        <i class="layui-icon layui-icon-search"></i>
                        <span>查询</span>
                    </a>
                    <a class="layui-btn layui-btn-sm" lay-event="add">
                        <i class="layui-icon layui-icon-add-1"></i>
                        <span>添加</span>
                    </a>
                    <a class="layui-btn layui-btn-sm" lay-event="del">
                        <i class="layui-icon layui-icon-delete"></i>
                        <span>删除</span>
                    </a>
                    <a class="layui-btn layui-btn-sm" lay-event="reset">
                        <i class="layui-icon layui-icon-refresh"></i>
                        <span>重置</span>
                    </a>
                </div>
                <form class="layui-form" action="" style="margin-top:10px" lay-filter="source">
                    <div class="table-top-filter">
                        <div class="table-filter-alone">
                            <label class="layui-form-label">规则名 </label>
                            <input type="text" name="Q_name_SL" id="name" class="layui-input filter-value"
                                   placeholder="规则名"
                                   autocomplete="off"/>
                        </div>
                        <div class="table-filter-alone">
                            <label class="layui-form-label">别名 </label>
                            <input type="text" name="Q_alias_SL" id="alias" class="layui-input filter-value"
                                   placeholder="别名"
                                   autocomplete="off"/>
                        </div>
                    </div>
                </form>
            </div>
        </script>

        <script type="text/html" id="manageBar">
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs" lay-event="detail">明细</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
        <script>
            layui.config({
                base: serverPath.formPath + staticPath.formPath //静态资源所在路径
            }).extend({
                index: 'index' //主入口模块
            }).use(['index', 'setter', 'commons', 'form', 'jquery', 'layer', 'common', 'table', 'totalFilter'], function () {
                var table = layui.table, layer = layui.layer, setter = layui.setter, commons = layui.commons,
                    common = layui.common,
                    totalFilter = layui.totalFilter;
                var tableH = commons.tabHeight();
                common.tableSort("formRule");
                //渲染表格
                table.render({
                    elem: '#formRule'
                    , cellMinWidth: 80
                    , title: '表单验证规则表'
                    , defaultToolbar: []
                    , height: tableH
                    , url: serverPath.formPath + setter.formLinkPath + 'formRule/list'
                    , toolbar: '#formRuleToolsBar'
                    , page: true
                    , autoSort: false
                    , cols: [[
                        {type: 'checkbox', fixed: 'left'}
                        , {field: 'name', title: '规则名', sort: true, align: 'center'}
                        , {field: 'alias', title: '别名', sort: true, align: 'center'}
                        , {field: 'rule', title: '规则', align: 'center'}
                        , {field: 'tipInfo', title: '错误提示信息', align: 'center'}
                        , {field: 'memo', title: '描述', sort: true, align: 'center'}
                        , {fixed: 'right', title: '管理', toolbar: '#manageBar', width: 180, align: 'center'}
                    ]]
                    , done: function () {
                        common.tableSelectCon('.ccpui-enterSel .layui-form input', 'a[lay-event=query]', '.ccpui-enterSel')
                    }
                });
                totalFilter.init('formRule');
                table.on('toolbar(formRule)', function (obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    var data = checkStatus.data; //获取选中行数据
                    switch (obj.event) {
                        case 'query':
                            common.tableConditionRender("formRule", "source", {where: {}}, false);
                            break;
                        case 'del':
                            if (data.length === 0) {
                                layer.confirm('请选择记录！', {
                                    btn: ['确定'] //按钮
                                }, function (index) {
                                    layer.close(index);
                                });
                            } else {
                                layer.confirm('确定删除当前选中的数据吗？', function (index) {
                                    var ids = [];
                                    for (var i = 0; i < data.length; i++) {
                                        ids.push(data[i].id);
                                    }
                                    var ruleIds = ids.join(',');
                                    $.ajax({
                                        url: serverPath.formPath + setter.formLinkPath + "formRule/del",
                                        data: {"ruleIds": ruleIds},
                                        dataType: 'json',
                                        success: function (data) {
                                            layer.alert(data.msg);
                                            //执行重载
                                            table.reload('formRule', {
                                                page: {
                                                    curr: 1
                                                }
                                            });
                                            totalFilter.init('formRule');
                                        }
                                    })
                                });
                            }
                            break;
                        case 'add':
                            layer.open({
                                type: 2,
                                title: "添加",
                                shade: 0.3,
                                area: ['600px', '400px'],
                                content: serverPath.formPath + setter.formLinkPath + "formRule/view/add"
                            });
                            break;
                        case 'reset':
                            common.tableConditionRender("formRule", "source", {where: {}}, true);
                            break;
                    }
                });
                //监听行工具事件
                table.on('tool(formRule)', function (obj) {
                    var data = obj.data;
                    switch (obj.event) {
                        case 'detail':
                            layer.open({
                                type: 2,
                                title: "明细",
                                shade: 0.3,
                                area: ['600px', '400px'],
                                content: serverPath.formPath + setter.formLinkPath + "formRule/view/detail?ruleId=" + data.id
                            });
                            break;
                        case 'del':
                            layer.confirm('确定删除当前数据吗？', function (index) {
                                var selId = obj.data.id;
                                var t_date = {};
                                t_date.ruleIds = selId;
                                $.ajax({
                                    url: serverPath.formPath + setter.formLinkPath + "formRule/del",
                                    data: t_date,
                                    dataType: 'json',
                                    success: function (data) {
                                        layer.alert(data.msg);
                                        //执行重载
                                        table.reload('formRule', {
                                            page: {
                                                curr: 1
                                            }
                                        });
                                        totalFilter.init('formRule');
                                    }
                                })
                            });
                            break;
                        case 'edit':
                            var oid = obj.data.id;
                            layer.open({
                                type: 2
                                ,
                                title: "编辑"
                                ,
                                content: serverPath.formPath + setter.formLinkPath + 'formRule/view/add?ruleId=' + oid
                                ,
                                area: ['600px', '400px']
                            });
                            break;
                    }
                });
            });
        </script>
    </body>
</html>
<link rel="stylesheet" href="${ctx}/css/font/iconfontie.css" media="all"/>
<link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
